package com.salt.admin.resource;

import com.github.pagehelper.PageHelper;
import com.salt.common.RestResponse;
import com.salt.system.mapper.SysUserMapper;
import com.salt.system.model.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * 管理 系统用户资源
 *
 * @author HaiBo Kuang
 * @date 2021/4/18 15:33
 */
@RestController
@RequestMapping("/admin/sys_user")
public class SysUserResource {
    private SysUserMapper userMapper;

    @Autowired
    public void setSysUserResource(SysUserMapper userMapper) {
        this.userMapper = userMapper;
    }

    /**
     * 系统用户列表
     *
     * @param query 查询 条件
     * @return 结果
     */
    @GetMapping("/list")
    public ResponseEntity<?> list(SysUser query) {
        if (Objects.nonNull(query.getPage()) && Objects.nonNull(query.getRows())) {
            return RestResponse.success(PageHelper.
                    startPage(query.getPage(), query.getRows()).
                    doSelectPageInfo(() -> userMapper.select(query)));
        }
        return RestResponse.success(userMapper.select(query));
    }
}
